import { request } from '@umijs/max';
import { Page, Result } from '../API';

export interface EUser {
  userId: string; //会员id
  name: string; //会员
  phone: string; //手机号码
  status: number; //状态 1-正常  2-禁用
  level: string; //技术等级
  technically: number; //技术分
  createTime: string; //创建时间-注册时间
}
export async function queryPage(
  params: {
    name?: string;
    phone?: string;
    status: number;
    current?: number;
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<Result<Page<EUser>>>('/pc/user/page', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * 查询详情
 * @param userId 用户id
 * @returns
 */
export async function queryUserInfo(userId: string) {
  return request<Result<EUser>>('/pc/user/Info', {
    method: 'GET',
    params: {
      userId: userId,
    },
  });
}

/**
 * 更新状态
 * @param userId 用户id  state 1-正常  2-禁用，reason：原因
 * @returns
 */
export async function editState(
  userId: string,
  state: number,
  reason?: string,
) {
  return request<Result<Boolean>>('/pc/user/editState', {
    method: 'POST',
    params: {
      userId: userId,
      state: state,
      reason: reason,
    },
  });
}

/**
 * 更新技术分
 * @param userId 用户id  technically 技术分 reason：原因
 * @returns
 */
export async function editTechnically(
  params: {
    userId: string,
    newTechnically: string,
    reason?: string,
  }
) {
  return request<Result<Boolean>>('/pc/user/editTechnically', {
    method: 'POST',
    params: {
      ...params
    },
  });
}

/**
 * 新增
 * @param userId 用户id
 * @returns
 */
export async function addUserInfo(params: EUser) {
  return request<Result<Boolean>>('/pc/user/add', {
    method: 'POST',
    params: {
      ...params,
    },
  });
}
/**
 * 编辑
 * @param userId 用户id
 * @returns
 */
export async function editUserInfo(params: EUser) {
  return request<Result<Boolean>>('/pc/user/edit', {
    method: 'POST',
    params: {
      ...params,
    },
  });
}
